﻿@model IList<ExamPlat.ViewModels.ViewExamQuesItem>
@{
    ViewBag.Title = "Index";
}
<div>
    <form action="/ExamQuesItem/Index">
        <table>
            <tr>
                <td>
                    <select name="searchExamID" id="searchExamID" style="width:160px;height:22px; margin-right:10px;">
                        <option value="0">--请选择--</option>
                        @{
                            if (ViewBag.ExamQuesList != null)
                            {
                                IList<ExamPlat.Models.ExamQues> list = ViewBag.ExamQuesList as IList<ExamPlat.Models.ExamQues>;
                                foreach (var item in list)
                                {
                                    if (ViewBag.SearchExamID == item.ID)
                                    {
                                        <option value="@item.ID" selected="selected">@item.ExamQuesTitle</option>
                                    }
                                    else
                                    {
                                        <option value="@item.ID">@item.ExamQuesTitle</option>
                                    }
                                }
                            }
                        }
                    </select>
                </td>
                <td>
                    <select name="searchType" id="searchType" style="width:160px; height:22px;  margin-right:10px;">
                        <option value="0">--请选择--</option>
                        @{
                            if (ViewBag.SearchType == 1)
                            {
                                <option value="1" selected="selected">单选题</option>
                            }
                            else
                            {
                                <option value="1">单选题</option>
                            }
                            if (ViewBag.SearchType == 2)
                            {
                                <option value="2" selected="selected">多选题</option>
                            }
                            else
                            {
                                <option value="2">多选题</option>
                            }
                            if (ViewBag.SearchType == 3)
                            {
                                <option value="3" selected="selected">对错题</option>
                            }
                            else
                            {
                                <option value="3">对错题</option>
                            }
                        }
                    </select>
                </td>
                <td><input type="text" id="searchTitle" name="searchTitle" value="@ViewBag.SearchTitle" placeholder="考题问题" /></td>
                <td style="padding-left:10px;"><input class="btn btn-primary" type="submit" value="查询" /></td>
                <td style="padding-left:10px;"><input type="button" value="增加" id="btnAdd" class="btn btn-primary" /></td>
            </tr>
        </table>
    </form>
</div>
<div>
    <table style="width:600px;">
        <tr><th>考题标题</th><th>问题</th><th>问题类型</th><th>问题分值</th><th>问题标准答案</th><th>操作</th></tr>
        @{
            if (Model != null)
            {
                foreach (var item in Model)
                {
                    string strType = "";
                    if (item.ExamQuesItemType == 1)
                    {
                        strType = "单选题";
                    }
                    if (item.ExamQuesItemType == 2)
                    {
                        strType = "多选题";
                    }
                    if (item.ExamQuesItemType == 3)
                    {
                        strType = "对错题";
                    }
                    <tr><td>@item.ExamQuesTitle</td><td>@item.ExamQuesItemTitle</td><td>@strType</td><td>@item.ExamQuesItemScore</td><td>@item.ExamQuesItemAnswer</td><td><a href="javascript:;" onclick="EditExamQues(@item.ID)">修改</a> <span style="padding-left:10px;"><a href="javascript:;" onclick="DelExamQuesTitle(@item.ID,'@item.ExamQuesTitle')">删除</a></span></td></tr>
                }
            }
        }
    </table>
</div>
<script type="text/javascript">
    function DelExamQuesTitle(id, name) {
        if (confirm('删除问题会一起删掉该问题下面的问题选项，确定删除' + name + '?')) {
            $.ajax({
                type: "post",  //提交方式
                url: "Delete",//路径
                data: { "id": id },//数据，这里使用的是Json格式进行传输
                dataType: "json",
                success: function (result) {//返回数据根据结果进行相应的处理
                    alert(result.msg);
                    window.location.reload();
                }
            });
        }
    }

    function EditExamQues(id) {
        window.location = "/ExamQuesItem/Edit?id=" + id + "&searchExamID=" + $("#searchExamID").val() + "&searchTitle=" + encodeURIComponent($("#searchTitle").val()) + "&searchType=" + $("#searchType").val();
    }

    $(function () {
        $("#btnAdd").click(function () {
            window.location = "/ExamQuesItem/Create?searchExamID=" + $("#searchExamID").val() + "&searchTitle=" + encodeURIComponent($("#searchTitle").val()) + "&searchType=" + $("#searchType").val();
        });
    });
</script>